﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using WalkingTec.Mvvm.Core;
using System.Text.Json.Serialization;
using nERP.Model;
using nERP.Model.Po;
using nERP.Model.Wms;
using nERP.Model.Fin;

namespace nERP.Model.Bas
{
    /// <summary>
    /// 供应商
    /// </summary>
	[Table("Supplier")]
    [SoftKey(nameof(Supplier.SupplierCode))]
    [Display(Name = "_Model.Supplier")]
    public class Supplier : BasePoco,IPersistPoco,ITenant
    {
        [Display(Name = "_Model._Supplier._SupplierCode")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("供应商编码")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [CanNotEdit]
        public string SupplierCode { get; set; }
        [Display(Name = "_Model._Supplier._SupplierName")]
        [StringLength(64, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("供应商名称")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public string SupplierName { get; set; }
        [Display(Name = "_Model._Supplier._ContactPerson")]
        [StringLength(64, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("联系人")]
        public string ContactPerson { get; set; }
        [Display(Name = "_Model._Supplier._PhoneNumber")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("手机号码")]
        [RegularExpression("^[1][345789][0-9]{9}$", ErrorMessage = "Validate.{0}formaterror")]
        public string PhoneNumber { get; set; }
        [Display(Name = "_Model._Supplier._Email")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("邮箱")]
        [RegularExpression("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$", ErrorMessage = "Validate.{0}formaterror")]
        public string Email { get; set; }
        [Display(Name = "_Model._Supplier._Faxing")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("传真")]
        public string Faxing { get; set; }
        [Display(Name = "_Model._Supplier._BeginPay")]
        [Comment("期初应付")]
        public decimal? BeginPay { get; set; }
        [Display(Name = "_Model._Supplier._EndPay")]
        [Comment("期末应付")]
        public decimal? EndPay { get; set; }
        [Display(Name = "_Model._Supplier._TaxtRate")]
        [Comment("税率")]
        public decimal? TaxtRate { get; set; }
        [Display(Name = "_Model._Supplier._Address")]
        [StringLength(256, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("地址")]
        public string Address { get; set; }
        [Display(Name = "_Model._Supplier._Bank")]
        [StringLength(256, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("开户行")]
        public string Bank { get; set; }
        [Display(Name = "_Model._Supplier._TaxpayerNumber")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("纳税人识别号")]
        public string TaxpayerNumber { get; set; }
        [Display(Name = "_Model._Supplier._BankAccount")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("银行账号")]
        public string BankAccount { get; set; }
        [Display(Name = "_Model._Supplier._LandlinePhone")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("固定电话")]
        [RegularExpression("^[-0-9\\s]{8,30}$", ErrorMessage = "Validate.{0}formaterror")]
        public string LandlinePhone { get; set; }
        [Display(Name = "_Model._Supplier._Remark")]
        [StringLength(256, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("备注")]
        public string Remark { get; set; }
        [Display(Name = "_Model._Supplier._SupplierFile")]
        [Comment("供应商附件")]
        public List<SupplierSupplierFile> SupplierFile { get; set; }
        [Display(Name = "_Model._Buy._Supplier")]
        [InverseProperty("Supplier")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Po.Buy.SupplierId))]
        public List<Buy> Buy_Supplier { get; set; }
        [Display(Name = "_Model._BuyReturn._Supplier")]
        [InverseProperty("Supplier")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Po.BuyReturn.SupplierId))]
        public List<BuyReturn> BuyReturn_Supplier { get; set; }
        [Display(Name = "_Model._BuyInWarehouse._Supplier")]
        [InverseProperty("Supplier")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.BuyInWarehouse.SupplierId))]
        public List<BuyInWarehouse> BuyInWarehouse_Supplier { get; set; }
        [Display(Name = "_Model._BuyReturnOutWarehouse._Supplier")]
        [InverseProperty("Supplier")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.BuyReturnOutWarehouse.SupplierId))]
        public List<BuyReturnOutWarehouse> BuyReturnOutWarehouse_Supplier { get; set; }
        [Display(Name = "_Model._Payment._Supplier")]
        [InverseProperty("Supplier")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Fin.Payment.SupplierId))]
        public List<Payment> Payment_Supplier { get; set; }
        [Display(Name = "_Model._OtherOutlay._Supplier")]
        [InverseProperty("Supplier")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Fin.OtherOutlay.SupplierId))]
        public List<OtherOutlay> OtherOutlay_Supplier { get; set; }
        [Display(Name = "_Model._Supplier._IsValid")]
        [Comment("是否有效")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public bool IsValid { get; set; } = true;
        [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
        public string TenantCode { get; set; }

    }
    public class SupplierSupplierFile : TopBasePoco, ISubFile
    {
        public Guid SupplierId { get; set; }
        public Supplier Supplier { get; set; }
        public Guid FileId { get; set; }
        public FileAttachment File { get; set; }
        public int Order { get; set; }
    }

}
